package Practicas.practica3;


import data.IntegerDataSetGenerator;
import impl.HSorter;
import test.BenchMark;

import java.util.ArrayList;
import java.util.Collections;

public class TestHSorter {
    private ArrayList<Integer> list;


    private void testHSorterMilis(int valor, int h) {
        list = new ArrayList<Integer>(valor);
        IntegerDataSetGenerator integerDataSetGenerator = new IntegerDataSetGenerator();
        HSorter hSorter = new HSorter();
        BenchMark benchMark = new BenchMark();
        hSorter.addSorterListener(benchMark);
        float random;
        random = 0;

        list = (ArrayList<Integer>) integerDataSetGenerator.createAscending(valor);
        Collections.shuffle(list);
        long tiempoRan1 = System.currentTimeMillis();
        hSorter.sort(integerDataSetGenerator.getComparator(), list, h);
        long tiempoRan2 = System.currentTimeMillis();
        random = tiempoRan2 - tiempoRan1;
        int swapsRamdon = benchMark.getnSwap();
        int comparationsRandom = benchMark.getComparations();
        benchMark.resetAll();
        System.out.println("||Cant: " + valor + "||Random (milis): " + random +"||" + "H: " + h);
        System.out.println("||Comp: " + comparationsRandom);
        System.out.println("||Swaps: " + swapsRamdon);
        System.out.println("");
    }

    public static void main(String[] args) {

        TestHSorter ths = new TestHSorter();
        int[] valores = {100, 1000, 10000, 50000};
        int[] h1 = {1, 8, 23, 77, 281, 1073, 4194, 1657};
        int[] h2 = {1, 4, 13, 40, 121, 363, 1093, 3280, 9841};


        System.out.println("Millis con h1");
        for (int k = 0; k < valores.length; k++) {
            for (int l = 0; l < h1.length; l++) {
                ths.testHSorterMilis(valores[k], h1[l]);

            }
        }
        System.out.println("Millis con h2");
        for (int k = 0; k < valores.length; k++) {
            for (int l = 0; l < h1.length; l++) {
                ths.testHSorterMilis(valores[k], h2[l]);

            }
        }


    }


}
